<template>
  <el-card>
    <div slot="header" class="clearfix">
      <span>结束节点属性</span>
    </div>
    <el-form-item label="编号">
      <el-input v-model="id" />
    </el-form-item>
    <el-form-item label="名称">
      <el-input v-model="name" />
    </el-form-item>
  </el-card>
</template>
<script>
export default {
  props: {
    element: {
      required: false,
      type: Object,
      default: null
    }
  },
  inject: ['bpmnModeler'],
  data() {
    return {
      id: this.element.id || '',
      name: '',
      formKey: '',
      documentation: ''
    }
  },

  watch: {
    id: function(newVal, oldVal) {
      const bpmnModeler = this.bpmnModeler()
      const modeling = bpmnModeler.get('modeling')
      modeling.updateProperties(this.element, {
        id: newVal
      })
    },
    name: function(newVal, oldVal) {
      const bpmnModeler = this.bpmnModeler()
      const modeling = bpmnModeler.get('modeling')
      modeling.updateProperties(this.element, {
        name: newVal
      })
    },
    element: {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
          if (newVal.type === 'bpmn:EndEvent') { // 防止修改其他子组件的属性
            const businessObject = newVal.businessObject
            this.name = businessObject.name
          }
        }
      },
      immediate: true,
      deep: true

    }
  }
}
</script>
<style>

</style>
